package com.grass.p019lv.fragment.search;

import android.os.Bundle;
import android.view.View;
import androidx.recyclerview.widget.GridLayoutManager;
import com.androidsa.bttsddka.R;
import com.androidx.p013lv.base.bean.VideoBean;
import com.androidx.p013lv.base.bean.VideoListBean;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.http.HttpUtils;
import com.androidx.p013lv.base.http.UrlManager;
import com.androidx.p013lv.base.http.callback.HttpCallback;
import com.androidx.p013lv.base.interfaces.Key;
import com.androidx.p013lv.base.listener.ItemClickListener;
import com.androidx.p013lv.base.p015ui.LazyFragment;
import com.androidx.p013lv.base.utils.NetUtil;
import com.androidx.p013lv.base.utils.ToastUtils;
import com.androidx.p013lv.invention.adapter.AdapterInvention;
import com.grass.p019lv.databinding.FragmentSearchBinding;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

/* renamed from: com.grass.lv.fragment.search.SearchVideoFragment */
public class SearchVideoFragment extends LazyFragment<FragmentSearchBinding> implements OnRefreshListener, OnLoadMoreListener {
    String VIDEO_BY_TITLE = "VideoByTitle";
    AdapterInvention adapter;
    int lastId;
    String searchTxt;

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public int setFragmentView() {
        return R.layout.fragment_search;
    }

    public static SearchVideoFragment newInstance(String str) {
        Bundle bundle = new Bundle();
        bundle.putString(Key.TXT, str);
        SearchVideoFragment searchVideoFragment = new SearchVideoFragment();
        searchVideoFragment.setArguments(bundle);
        return searchVideoFragment;
    }

    @Override // androidx.fragment.app.Fragment
    public void setArguments(Bundle bundle) {
        super.setArguments(bundle);
        this.searchTxt = bundle.getString(Key.TXT);
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public void initViews() {
        ((FragmentSearchBinding) this.binding).refresh.setOnRefreshListener(this);
        ((FragmentSearchBinding) this.binding).refresh.setOnLoadMoreListener(this);
        ((FragmentSearchBinding) this.binding).recycler.setLayoutManager(new GridLayoutManager(getActivity(), 2));
        this.adapter = new AdapterInvention();
        ((FragmentSearchBinding) this.binding).recycler.setAdapter(this.adapter);
        this.adapter.setItemListener(new ItemClickListener() {
            /* class com.grass.p019lv.fragment.search.SearchVideoFragment.C30121 */

            @Override // com.androidx.p013lv.base.listener.ItemClickListener
            public void onItemClick(View view, int i) {
                SearchVideoFragment searchVideoFragment = SearchVideoFragment.this;
                searchVideoFragment.startVideoPlay(((VideoBean) searchVideoFragment.adapter.getDataInPosition(i)).getVideoId());
            }
        });
        ((FragmentSearchBinding) this.binding).statusLayout.setOnRetryListener(new View.OnClickListener() {
            /* class com.grass.p019lv.fragment.search.SearchVideoFragment.View$OnClickListenerC30132 */

            public void onClick(View view) {
                SearchVideoFragment.this.lastId = 0;
                SearchVideoFragment.this.getInfo();
            }
        });
        getInfo();
    }

    /* access modifiers changed from: package-private */
    public void getInfo() {
        if (this.lastId == 0) {
            AdapterInvention adapterInvention = this.adapter;
            if (!(adapterInvention == null || adapterInvention.getData() == null || this.adapter.getData().size() <= 0)) {
                this.adapter.clear();
            }
            if (!NetUtil.isNetworkAvailable()) {
                ((FragmentSearchBinding) this.binding).statusLayout.showNoNet();
                return;
            }
            ((FragmentSearchBinding) this.binding).statusLayout.showLoading();
        }
        HttpUtils.getInsatance().get(UrlManager.getInsatance().queryVideoByTitleNew(this.searchTxt, this.lastId), new HttpCallback<BaseRes<VideoListBean>>(this.VIDEO_BY_TITLE) {
            /* class com.grass.p019lv.fragment.search.SearchVideoFragment.C30143 */

            public void onLvSuccess(BaseRes<VideoListBean> baseRes) {
                if (SearchVideoFragment.this.binding != null) {
                    ((FragmentSearchBinding) SearchVideoFragment.this.binding).statusLayout.hideLoading();
                    ((FragmentSearchBinding) SearchVideoFragment.this.binding).refresh.finishRefresh();
                    ((FragmentSearchBinding) SearchVideoFragment.this.binding).refresh.finishLoadMore();
                    if (baseRes.getCode() == 200) {
                        if (baseRes.getData() == null || baseRes.getData().getList() == null || baseRes.getData().getList().size() <= 0) {
                            if (SearchVideoFragment.this.lastId == 0) {
                                ((FragmentSearchBinding) SearchVideoFragment.this.binding).statusLayout.showEmpty();
                            } else {
                                ((FragmentSearchBinding) SearchVideoFragment.this.binding).refresh.finishLoadMoreWithNoMoreData();
                            }
                        } else if (SearchVideoFragment.this.lastId == 0) {
                            SearchVideoFragment.this.adapter.setDomain(baseRes.getData().getDomain());
                            SearchVideoFragment.this.adapter.setData(baseRes.getData().getList());
                            ((FragmentSearchBinding) SearchVideoFragment.this.binding).refresh.resetNoMoreData();
                        } else {
                            SearchVideoFragment.this.adapter.setDatasInEnd(baseRes.getData().getList());
                        }
                    } else if (SearchVideoFragment.this.lastId == 0) {
                        ((FragmentSearchBinding) SearchVideoFragment.this.binding).statusLayout.showError();
                    } else {
                        ToastUtils.getInstance().showWeak(baseRes.getMsg());
                    }
                }
            }
        });
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnRefreshListener
    public void onRefresh(RefreshLayout refreshLayout) {
        this.lastId = 0;
        getInfo();
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnLoadMoreListener
    public void onLoadMore(RefreshLayout refreshLayout) {
        AdapterInvention adapterInvention = this.adapter;
        if (adapterInvention == null || adapterInvention.getData() == null || this.adapter.getData().size() == 0) {
            ((FragmentSearchBinding) this.binding).refresh.finishLoadMore();
            return;
        }
        this.lastId = ((VideoBean) this.adapter.getLastDataInPosition()).getVideoId();
        getInfo();
    }

    @Override // androidx.fragment.app.Fragment, com.gyf.immersionbar.components.ImmersionFragment
    public void onDestroy() {
        HttpUtils.getInsatance().cancelTag(this.VIDEO_BY_TITLE);
        super.onDestroy();
    }
}
